#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include "rtp.h"

#define SERVER_RTSP_PORT       	 8554
#define SERVER_RTP_PORT        	 66698
#define SERVER_RTCP_PORT       	 SERVER_RTP_PORT + 1
#define BUF_MAX_SIZE           	 (2*1024*1024)
#define MAX_H264_FILE_NAME_LENTH        256


class Rtsp{
public:
	char mH264FileName[MAX_H264_FILE_NAME_LENTH];
	Rtp * mRtp;
	int serverRtspSockfd;
    	int serverRtpSockfd;
	int serverRtcpSockfd;
	int clientRtpPort;
	int clientRtcpPort;

	Rtsp(char * FileName);
	~Rtsp();
	int createSocket(int tcpOrUdp);
	int bindSocketAddr(int sockfd, const char* ip, int port);
	int acceptClient(int sockfd, char* ip, int* port);
	char* getLineFromBuf(char* buf, char* line);
	int handleOptions(char* result, int cseq);
	int handleDescribe(char* result, int cseq, char* url);
    	int handleSetup(char* result, int cseq, int clientRtpPort);
	int handlePlay(char* result, int cseq);
	int handleTeardown(char* result, int cseq);	
	void  responseToClient(int clientSockfd, const char* clientIP, int clientPort,int serverRtpSockfd, int serverRtcpSockfd);
	int running();
};
